package homework.h03;

/**
 * @author thinkpad - 83start
 * @version v1.0
 * @create 2022/10/6 20:08
 * @package homework.h03
 * @description 文件说明
 */

public class Rectangle {
    private double length;
    private double width;

    public Rectangle() {
    }

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    public double getLength() {
        return length;
    }

    public double getWidth() {
        return width;
    }

    public double area() {
        return length * width;
    }

    public double perimeter() {
        return 2 * (width + length);
    }


    public String print() {
        return "length=" + length +
                ", width=" + width;
    }
}

class Box extends Rectangle {
    private double height;

    public Box() {
    }

    public Box(double height) {
        this.height = height;
    }

    public Box(double length, double width, double height) {
        super(length, width);
        this.height = height;
    }

    public double getHeight() {
        return height;
    }

    /**
     * 获取面积
     *
     * @return
     */
    @Override
    public double area() {
        return 2 * (
                getRectangleArea(super.getLength(), super.getWidth()) +
                        getRectangleArea(super.getLength(), height) +
                        getRectangleArea(super.getWidth(), height)
        );

    }

    /**
     * 获取体积
     *
     * @return
     */
    public double volume() {
        return height * super.getLength() * super.getWidth();
    }

    @Override
    public String print() {
        return
                "height=" + height + ", " + super.print();
    }

    private double getRectangleArea(double a, double b) {
        return a * b;
    }

    public static void main(String[] args) {
        // 矩形
        Rectangle rectangle = new Rectangle(12, 21);
        System.out.println("面积：" + rectangle.area());
        System.out.println("周长" + rectangle.perimeter());
        System.out.println("矩形信息：" + rectangle.print());


        Box box = new Box(12, 21, 21);
        System.out.println("面积：" + box.area());
        System.out.println("体积：" + box.volume());
        System.out.println("立方体信息：" + box.print());
    }
}


